package org.deadline.model.baseapp;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.config.Enumeration;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class SMSNotification extends BaseEntity  implements Serializable {

    @ManyToOne
    private Principal smsFrom;

    @NotNull
    @Size(min = 2, max = 500)
    private String smsTo;

    @NotNull
    @Size(min = 2, max = 255)
    private String subject;

    @NotNull
    @Size(min = 2, max = 2000)
    private String message;

    @NotNull
    @Size(min = 2, max = 255)
    private String comment;

    @ManyToOne
    private Enumeration notifyStatus;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="sms_notification_seq_gen",sequenceName="sms_notification_seq")
	@GeneratedValue(generator="sms_notification_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static SMSNotification fromJsonToSMSNotification(String json) {
        return new JSONDeserializer<SMSNotification>().use(null, SMSNotification.class).deserialize(json);
    }

	public static String toJsonArray(Collection<SMSNotification> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<SMSNotification> fromJsonArrayToSMSNotifications(String json) {
        return new JSONDeserializer<List<SMSNotification>>().use(null, ArrayList.class).use("values", SMSNotification.class).deserialize(json);
    }

	private static final long serialVersionUID = 1L;

	public Principal getSmsFrom() {
        return this.smsFrom;
    }

	public void setSmsFrom(Principal smsFrom) {
        this.smsFrom = smsFrom;
    }

	public String getSmsTo() {
        return this.smsTo;
    }

	public void setSmsTo(String smsTo) {
        this.smsTo = smsTo;
    }

	public String getSubject() {
        return this.subject;
    }

	public void setSubject(String subject) {
        this.subject = subject;
    }

	public String getMessage() {
        return this.message;
    }

	public void setMessage(String message) {
        this.message = message;
    }

	public String getComment() {
        return this.comment;
    }

	public void setComment(String comment) {
        this.comment = comment;
    }

	public Enumeration getNotifyStatus() {
        return this.notifyStatus;
    }

	public void setNotifyStatus(Enumeration notifyStatus) {
        this.notifyStatus = notifyStatus;
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}

	}
